package com.yimu.lib.Receiver;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;

import com.yimu.lib.base.BaseApplication;
import com.yimu.lib.util.MyLogger;


import java.util.List;
/**
 * 描述：广播Notify
 * 创建者：  Churck
 * 创建时间：16/7/7 15:56
 * 修改者： Churck
 * 修改时间：16/7/7 15:56
 * 版 本：v1.0
 */
public class AndroidNotify implements AppNotify.NotifyHandler {
	private static final LocalBroadcastManager mgr = LocalBroadcastManager.getInstance(BaseApplication.getInstance().getApplicationContext());

	public static void registerReceiver(BroadcastReceiver receiver, List<String> list) {
		if (receiver == null)
			return;
		mgr.unregisterReceiver(receiver);
		if (list != null && list.size() > 0) {
			IntentFilter filter = new IntentFilter();
			for (String action : list)
				filter.addAction(action);
			mgr.registerReceiver(receiver, filter);
		}
	}

	public static void unregisterReceiver(BroadcastReceiver receiver) {
		if (receiver != null) {
			mgr.unregisterReceiver(receiver);
		}
	}

	@Override
	public void OnNotify(String action, String param) {
		Intent intent = new Intent(action);
		intent.putExtra("param", param);
		MyLogger.d("发送广播了。。。。。。。。。。");
		mgr.sendBroadcast(intent);
	}
}
